/*
 * Project: BoboDesignPattern
 * 
 * File Created at 2019年12月8日
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package test.practice;

import java.util.Arrays;

/**
 * @Type A20191208_fastsort
 * @Desc
 * @author 52489
 * @date 2019年12月8日
 * @Version V1.0
 */
public class A20191208_fastsort {

    public static void main(String[] args) {
        int nums[] = { 3, 8, 1, 3, 3, 3, 2, 5, 7 };
        System.out.println(Arrays.toString(fastsort(0, nums.length - 1, nums)));
        ;
    }

    /**
     * @param i
     * @param j
     * @param nums
     */
    private static int[] fastsort(int start, int end, int[] nums) {
        if (start < end) {
            int left = start;
            int right = end;
            int tmp = nums[start];
            while (left < right) {
                while (nums[right] > tmp && left != right) {
                    right--;
                }
                while (nums[left] <= tmp && left != right) {
                    left++;
                }
                int k = nums[left];
                nums[left] = nums[right];
                nums[right] = k;
            }
            int k = nums[start];
            nums[start] = nums[left];
            nums[left] = k;
            fastsort(start, left - 1, nums);
            fastsort(left + 1, end, nums);
        }

        return nums;
    }

}
